package com.et114.modules.system.dictionary.tag;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.et114.modules.system.dictionary.DictionaryCache;
import com.et114.modules.system.dictionary.vo.BizType;

/**
 * @author 
 * 
 * ��Tag��4��ݸ��ҵ������ ���HTML <select> ��ǩ��<option>�б?
 *  ����ҵ������ID��Ϊ<option>��ǩ��value����
 *  ��ҵ������������Ϊ<option>��ǩ�ı�ǩ
 * eg. 
 * <option value="BNDICT_gender">�Ա�</option> 
 * <option value="BNDICT_race" selected>����</option>
 * 
 */
public class DictBizTypeTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected String selected; // ��ѡ��ҵ�����ʹ���ֵ

	/**
	 * @return
	 */
	public String getSelected() {
		return selected;
	}

	/**
	 * @param string
	 */
	public void setSelected(String string) {
		selected = string;
	}

	/**
	 * �����-��
	 */
	public int doEndTag() throws JspException {
		
		StringBuffer results = new StringBuffer();
		DictionaryCache cache = DictionaryCache.getInstance();
		List biztypes = cache.listBizTypes();
		System.out.println("-------type--------"+biztypes.size());
		for (Iterator it = biztypes.iterator(); it.hasNext();) {
			BizType bt=(BizType)it.next();
			results.append("<option value=\"");
			results.append(bt.getBizTypeId());
			results.append("\"");
			if (bt.getBizTypeId().equals(selected)) {
				results.append(" selected=\"selected\"");
			}
			results.append(">");
			results.append(bt.getBizTypeKey());

			results.append("</option>");
		}
		 JspWriter writer = pageContext.getOut();
		 try {
			writer.write(results.toString());
		} catch (IOException e) {
			 throw new JspException(e.getMessage());
		}
		 return (EVAL_PAGE);
	}

}
